const Koa = require('koa')
const app = new Koa()
const { connect, initSchemas } = require('./database/init.js')
// const mongoose = require('mongoose')
const cors = require('koa2-cors') // 用于解决前后端跨域问题
const bodyParser = require('koa-bodyparser')

app.use(cors())
app.use(bodyParser())

let api = require('./router/api.js')
app.use(api.routes())
app.use(api.allowedMethods())

// 立即执行函数
;(async () => {
  await connect()
  initSchemas()
})()

app.listen(3000)
console.log('监听3000端口')
